import { AxiosError } from 'axios';

export const getAxiosError = (error: unknown): AxiosError<{ message?: string }> | null => {
  if (error instanceof Error && 'isAxiosError' in error && error['isAxiosError'])
    return error as AxiosError<{ message?: string }>;

  return null;
};

/* -------------------------------------------------------------------------- */

export const getApiErrorMessage = (error: unknown): string =>
  getAxiosError(error)?.response?.data?.message || 'что-то пошло не так';
